<?php
                        
	$data = $store->getAllCategoryByIdPage($idpage);
	//print_r($data);exit;
	$category = null;
	foreach($data as $key=>$value)
	{
		$category[$value['parent_id']][] = $value;
	}
	echo menu($category, 0, $idpage);
	
	function menu($data = null,$parent = 0, $idpage=""){
		if($data == null) return;
		
		if($parent != 0)
			$link = APP_DOMAIN .'/category/?idpage='.$idpage.'&id=';
		else
			$link = APP_DOMAIN .'/category/?idpage='.$idpage.'&idp=';
		$str = '';
		if(isset($data[$parent])){
			$str .= '<ul>';
			foreach($data[$parent] as $rs){
				$id = isset($_GET['id']) ? $_GET['id'] : "";
				$idp = isset($_GET['idp']) ? $_GET['idp'] : "";
				$active = (($rs['idloaisp'] == $id) || ($rs['idp'] == $idp)) ? "class='active'" : "";
				
				$url = $link == "javascript:void(0)" ? $link : $link.$rs['idloaisp'];
				$str .= '<li '.$active.'><a href="'.$url.'">'.$rs['tenloaisp'].'</a>';
				$str .= menu($data,$rs['idloaisp'], $idpage);
				$str .= '</li>';
			}
			$str .= '</ul>';
		}
		return $str;
	}
?>